{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "456a1e22",
   "metadata": {},
   "source": [
    "# 列表方法总结"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a662dceb",
   "metadata": {},
   "source": [
    "| 列表方法   |说明               |示例    |备注   |\n",
    "| ----------- | ----------------       |-----------  |----------- |\n",
    "|append()   |增加元素在列表的末尾    |详见下方示例1|   无     |\n",
    "| count()    |  统计某个元素在列表中出现的次数  |详见下方示例2| 输出结果是出现次数,而不是列表元素的个数  |\n",
    "| extend()   |  在列表末尾一次性追加另一个序列中的多个值| 详见下方示例3| 增加的是一个字符串中的具体元素|\n",
    "| index()    | 从列表中找出某个值的索引位置 | 详见下方示例4|找到的索引位置为第一个匹配项|\n",
    "| pop()     | 移除列表中的一个元素 |详见下方示例5|默认最后一个元素|\n",
    "| insert()   |将指定对象插入列表的指定位置|详见下方示例6|结果是插入在指定元素的前面|\n",
    "| remove()   | 将某个元素从列表中移除|详见下方示例7|只移除某个元素的第一个匹配项|\n",
    "| reverse()  | 反向列表中的元素   |详见下方示例8|对列表的元素进行反向排序|\n",
    "| sort()    | 将列表中的元素进行排序|详见下方示例9|按首字母进行排序|\n",
    "| clear()   | 清空列表     |详见下方示例10|清除列表中的所有元素|\n",
    "| copy()    | 复制列表     |详见下方示例11|无|"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f0ddbb9f",
   "metadata": {},
   "source": [
    "## 1.append()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "ad5dd9b0",
   "metadata": {},
   "outputs": [],
   "source": [
    "names = [\"Mike\",\"Mary\",\"Jane\",\"Alex\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "65ac55a0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Mike', 'Mary', 'Jane', 'Alex', 'Tom']\n"
     ]
    }
   ],
   "source": [
    "names.append(\"Tom\")\n",
    "print (names)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2f59ea8e",
   "metadata": {},
   "source": [
    "## 2.count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "fbf40680",
   "metadata": {},
   "outputs": [],
   "source": [
    "list = [22,15,66,8,5,4,22,20,38,22,44]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "36a93e66",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list.count(22)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b2dd2927",
   "metadata": {},
   "source": [
    "## 3.extend()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "c53ba0ee",
   "metadata": {},
   "outputs": [],
   "source": [
    "names = [\"China\",\"America\",\"England\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "a1c89029",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['China', 'America', 'England', 'I', 't', 'a', 'l', 'y']"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names.extend(\"Italy\")\n",
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0e3d2d11",
   "metadata": {},
   "source": [
    "## 4.index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "13e3e559",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Mike\",\"Mary\",\"Jane\",\"Jack\",\"Mary\"]\n",
    "names.index(\"Mary\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "36b8c13f",
   "metadata": {},
   "source": [
    "## 5.pop()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "e365780f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Mary', 'Jane']"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Mike\",\"Mary\",\"Jane\",\"Alex\"]\n",
    "names.pop()\n",
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1826c217",
   "metadata": {},
   "source": [
    "## 6.insert()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "316b377b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Mary', 'Jane', 'Alex', 'Bob', 'Tom']"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Mike\",\"Mary\",\"Jane\",\"Alex\",\"Tom\"]\n",
    "names.insert(4,\"Bob\")\n",
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fe604841",
   "metadata": {},
   "source": [
    "## 7.remove()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "820f29a2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Mary', 'Alex', 'Jane']"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Mike\",\"Mary\",\"Jane\",\"Alex\",\"Jane\"]\n",
    "names.remove(\"Jane\")\n",
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "df4fdc02",
   "metadata": {},
   "source": [
    "## 8.reverse()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "a124450f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Alex', 'Jane', 'Mary', 'Mike']"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Mike\",\"Mary\",\"Jane\",\"Alex\"]\n",
    "names.reverse()\n",
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b84a4037",
   "metadata": {},
   "source": [
    "## 9.sort() "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "9b2b96f2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Alex', 'Jane', 'Mary', 'Mike', 'Tom']"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Mike\",\"Mary\",\"Jane\",\"Alex\",\"Tom\"]\n",
    "names.sort()\n",
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e33c4991",
   "metadata": {},
   "source": [
    "## 10.clear()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "b4726979",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Mike\",\"Mary\",\"Jane\",\"Alex\"]\n",
    "names.clear()\n",
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "378ade66",
   "metadata": {},
   "source": [
    "## 11.copy()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "b0cc98a4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Mike', 'Mary', 'Jane', 'Alex']\n"
     ]
    }
   ],
   "source": [
    "names = [\"Mike\",\"Mary\",\"Jane\",\"Alex\"]\n",
    "name02 = names.copy()\n",
    "print(name02)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
